namespace SimpleWebServices.Web.UI.Html.Elements
{
    using SimpleWebServices;
    using SimpleWebServices.Data;
    using SimpleWebServices.Web.UI.Html.Validation;
    using Xunit;

    public sealed class RadioFieldsetFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<RadioFieldset>()
                .DerivesFrom<Fieldset>()
                .IsAbstractBaseClass()
                .Implements<IControl>()
                .XmlRoot("fieldset")
                .Result);
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new RadioFieldsetDerived());
        }

        [Fact]
        public void ctor_Name_Legend()
        {
            Assert.NotNull(new RadioFieldsetDerived(new Name("name"), new Legend()));
        }

        [Fact]
        public void prop_Disabled()
        {
            Assert.True(new PropertyExpectations(typeof(RadioFieldsetDerived).GetProperty("Disabled"))
                .IsAutoProperty<bool>()
                .Result);
        }

        [Fact]
        public void prop_IsValid()
        {
            Assert.True(new PropertyExpectations(typeof(RadioFieldsetDerived).GetProperty("IsValid"))
                .TypeIs<bool>()
                .DefaultValueIs(true)
                .Result);
        }

        [Fact]
        public void prop_IsValid_getWithValidator()
        {
            RadioFieldset obj = new RadioFieldsetDerived();
            obj.Validator = new RadioFieldsetValidator(new Label());

            Assert.False(obj.IsValid);
        }

        [Fact]
        public void prop_Name_get()
        {
            RadioFieldset obj = (
                "<fieldset>" +
                    "<div>" +
                        "<input id='test' name='test' type='radio' value='123' checked='checked' />" +
                    "</div>" +
                "</fieldset>").Deserialize<RadioFieldsetDerived>();

            string expected = "test";
            string actual = obj.Name;

            Assert.Equal<string>(expected, actual);
        }

        [Fact]
        public void prop_Name_set()
        {
            RadioFieldset obj = (
                "<fieldset>" +
                    "<input id='test' name='foo' type='radio' value='123' />" +
                "</fieldset>").Deserialize<RadioFieldsetDerived>();

            string expected = "bar";

            obj.Name = expected;

            string actual = obj.Name;

            Assert.Equal<string>(expected, actual);
        }

        [Fact]
        public void prop_Suppress()
        {
            Assert.True(new PropertyExpectations(typeof(RadioFieldsetDerived).GetProperty("Suppress"))
                .IsAutoProperty<bool>()
                .Result);
        }

        [Fact]
        public void prop_TabIndex()
        {
            Assert.True(new PropertyExpectations(typeof(RadioFieldsetDerived).GetProperty("TabIndex"))
                .IsAutoProperty<int?>()
                .Result);
        }

        [Fact]
        public void prop_Validator()
        {
            Assert.True(new PropertyExpectations(typeof(RadioFieldsetDerived).GetProperty("Validator"))
                .IsAutoProperty<IValidate>()
                .Result);
        }

        [Fact]
        public void prop_Value_get()
        {
            RadioFieldset obj = (
                "<fieldset>" +
                    "<div>" +
                        "<input id='test' name='test' type='radio' value='123' checked='checked' />" +
                    "</div>" +
                "</fieldset>").Deserialize<RadioFieldsetDerived>();

            string expected = "123";
            string actual = obj.Value;

            Assert.Equal<string>(expected, actual);
        }

        [Fact]
        public void prop_Value_set()
        {
            RadioFieldset obj = (
                "<fieldset>" +
                    "<input id='test' name='test' type='radio' value='123' />" +
                "</fieldset>").Deserialize<RadioFieldsetDerived>();

            Assert.Null(obj.Value);

            string expected = "123";

            obj.Value = expected;

            string actual = obj.Value;

            Assert.Equal<string>(expected, actual);
        }

        [Fact]
        public void op_ToDataCollection()
        {
            RadioFieldset obj = (
                "<fieldset>" +
                    "<input id='test' name='test' type='radio' value='123' checked='checked' />" +
                "</fieldset>").Deserialize<RadioFieldsetDerived>();

            DataCollection expected = new DataCollection();
            expected.Add("test", "123");

            DataCollection actual = obj.ToDataCollection();

            Assert.Equal<DataCollection>(expected, actual);
        }

        [Fact]
        public void op_Update_Name_string()
        {
            RadioFieldset obj = (
                "<fieldset>" +
                    "<input id='test' name='test' type='radio' value='123' />" +
                "</fieldset>").Deserialize<RadioFieldsetDerived>();

            DataCollection expected = new DataCollection();
            expected.Add("test", "123");

            obj.Update("test", "123");

            DataCollection actual = obj.ToDataCollection();

            Assert.Equal<DataCollection>(expected, actual);
        }
    }
}